<template>
  <div class="goodsList">
    <div class="goods" v-for="(goods,index) in goodList" :key="goods.id" @click="toDetail">
      <van-image
        width="172.5"
        height="172.5"
        lazy-load
        :src="goods.goodsImg"
      />
      <div class="name">
        <img
          class="nameImg"
          :src="goods.logoUrl"
          alt=""
        />
        <span class="title">{{goods.name}}</span>
      </div>
      <div class="price">
        <span class="detail">￥</span>
        <span class="money">{{goods.price}}</span>
        <del class="delete" v-if="goods.counterPrice">￥{{goods.counterPrice}}</del>
      </div>
      <div></div>
      <div class="banner-wrap" :class="{'active':goods.logoInfo.title&&goods.logoInfo.content}">
        <div class="left">{{goods.logoInfo.title || goods.logoInfo.content}}</div>
        <div class="right" v-if="goods.logoInfo.title">{{goods.logoInfo.content}}</div>
      </div>
    </div>


  </div>
</template>

<script>
import {Dialog} from 'vant'
import {mapGetters} from 'vuex'
export default {
  name:'Goods',
  props:['isSearch'],
  data(){
    return{
      goodList:[]
    }
  },
 methods:{
   toDetail(){
     this.$router.push({name:'detail'})
   }
 },
  computed:{
    ...mapGetters(['goodsList'])
  },
  watch:{
    
    goodsList:{
      deep:true,
      handler(newValue){
        if(this.isSearch){
          this.goodList = []
        }else{
          this.goodList = newValue
           
        }
        if(!this.goodsList.length){
          this.$emit('update:keyword','')
          Dialog({ message: '您输入的商品不存在，请重新输入' });
          
        }

      }
    }
  }
};
</script>

<style lang='less' scoped>
.goodsList {
  width: 100%;
  display: flex;
  padding-bottom: 40px;
  flex-wrap: wrap;
  background-color: #fff;
  .goods {
    z-index: 0;
    width: 50%;
    height: 283.5px;
    padding: 10px 5px 26px 7px;
    // background-color: chartreuse;
    .banner-wrap {
      // height: 23px;
      // background-color: #ffe9eb;
      display: flex;
      border-radius: 30px;
      &.active {
        background-color: #ffe9eb;
      }
      .left {
        border-radius: 30px;
        padding: 0 5px;
        font-size: 12px;
        text-align: center;
        line-height: 23px;
        background-color: #fa1e32;
        color: #ffffff;
      }
      .right {
        font-size: 12px;
        margin-left: 5px;
        color: #fa1e32;
        line-height: 23px;
        font-size: 12px;
        font-weight: bold;
      }
    }
    .price {
      font-size: 20px;
      font-weight: bold;
      color: #fa1e32;
      .detail {
        font-weight: normal;
        font-size: 13px;
      }
      .delete {
        font-weight: normal;
        font-size: 13px;
        color: #999999;
        text-decoration: line-through;
      }
    }
    .name {
      margin: 5px 0;
      width: 175.5px;
      height: 39px;
      display: -webkit-box;
      -webkit-box-orient: vertical;
      -webkit-line-clamp: 2;
      overflow: hidden;
      .nameImg {
        width: 44px;
        height: 17px;
        margin-right: 5px;
      }
      .title {
        font-size: 14px;
      }
    }
  }
}
</style>